/*
 *	ME2 C++ SDK
 *	Copyright (c) 2010 _silencer
 *
 *	Permission is hereby granted, free of charge, to any person
 *	obtaining a copy of this software and associated documentation
 *	files (the "Software"), to deal in the Software without
 *	restriction, including without limitation the rights to use,
 *	copy, modify, merge, publish, distribute, sublicense, and/or sell
 *	copies of the Software, and to permit persons to whom the
 *	Software is furnished to do so, subject to the following
 *	conditions:
 *
 *	The above copyright notice and this permission notice shall be
 *	included in all copies or substantial portions of the Software.
 *
 *	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *	WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *	OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef DEMO_MOD_H
#define DEMO_MOD_H

#include "unreal_sdk.h"
#include "unreal_mod.h"

using namespace unreal;

extern uengine_interface& engine_interface;

void start_mod();
void stop_mod();

extern volatile bool console_active;
extern volatile bool console_wait;
extern volatile bool console_waiting;

inline void get_console()
{
	console_wait = true;

	if ( !console_waiting )
	{
		std::cin.putback( '\n' );

		while ( !console_waiting )
		{
		}
	}
}

inline void release_console()
{
	console_wait = false;
}

inline void terminate_console()
{
	console_active = false;
	console_wait = false;

	std::cin.putback( '\n' );
	std::cout << std::endl;
}

class scoped_get_console
{
public:

	scoped_get_console()
	{
		get_console();
	}

	~scoped_get_console()
	{
		release_console();
	}
};

class demo_mod: public uengine_mod
{
public:

	demo_mod();
	~demo_mod();
	void on_tick( float delta_time );
	void on_post_render( uobject* canvas );
	void on_level_change();

	void do_test_resize()
	{
		console_wait = true;
		do_test_resize_ = true;
	}

	void do_test_helmet()
	{
		console_wait = true;
		do_test_helmet_ = true;
	}

private:

	bool first_tick_;
	bool first_render_;
	volatile bool do_test_resize_;
	volatile bool do_test_helmet_;
};

extern boost::shared_ptr<demo_mod> demo_mod_ptr;

#endif
